********Figure J.1 - Indonesia********


*Load data
cd "$reploc/data/created_data"
use indo_full, clear


sort pidlink ifls
foreach var of varlist rbuc_garefined rbuc grbrprovAvg_lam0co3 grbrprovSD_lam0co3 inflation{
gen `var'dif=`var'-`var'[_n-1] if ifls==5 & pidlink==pidlink[_n-1]
} 

*Do these results for primary sample
egen coh_prov_clust=group(biryear_impl birprov_impl)

gen primarysample1=0
replace primarysample1=1 if rbuc_garefineddif!=. & grbrprovAvg_lam0co3dif!=. & grbrprovSD_lam0co3dif!=. & inflationdif!=. &  biryear_impl>=1961 & coh_prov_clust!=.

egen primarysample=total(primarysample1), by(pidlink)
keep if primarysample==1

*Plot
gen income_pc_monthly=income_pc/(12*1000)


local xvars income_pc_monthly NarrowBracket

foreach x in `xvars' {

*Truncate for graph
gen `x'_LB_ATRUNCATED=`x'_LB_A
gen `x'_UB_ATRUNCATED=`x'_UB_A

sum `x'_LB_A if `x'_LB_A!=-9999999
local minuse=r(min)
replace `x'_LB_ATRUNCATED=0 if `x'_LB_A<0
replace `x'_LB_ATRUNCATED=5 if `x'_LB_A>5

sum `x'_UB_A if `x'_UB_A!=9999999
local maxuse=r(max)
replace `x'_UB_ATRUNCATED=5 if `x'_UB_A>5
replace `x'_UB_ATRUNCATED=0 if `x'_UB_A<0



forval iflsi=4/5 {
if "`x'"!="NarrowBracket" {

*For graph, drop outliers
sum `x', d
drop if `x'>r(p99)
drop if `x'<0

local nam1 HH Income per capita


twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==1 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==2 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==3 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==4 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED `x' if rbuc==5 & ifls==`iflsi', msize(vsmall)), ytitle("Range of Structural Risk Aversion Parameter") xtitle("`nam1' (1000s of Rupiah)") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5")) graphregion(color(white))

cd "$reploc/results"
graph export figureJ1IndonesiaBroadifls`iflsi'.eps, replace
}

else {
capture drop id
gen id=_n
twoway (rspike `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==1 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==2 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==3 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==4 & ifls==`iflsi', msize(vsmall)) (rspike  `x'_UB_ATRUNCATED `x'_LB_ATRUNCATED id if rbuc==5 & ifls==`iflsi', msize(vsmall)), ytitle("Range of Structural Risk Aversion Parameter") xtitle("ID") legend(label(1 "Risk Av. Bucket 1") label(2 "Risk Av. Bucket 2") label(3 " Risk Av. Bucket 3") label(4 " Risk Av. Bucket 4") label(5 " Risk Av. Bucket 5")) graphregion(color(white))

cd "$reploc/results"
graph export FigureJ1IndonesiaNarrowifls`iflsi'.eps, replace

}

}
}
